package com.ruoyi.web.controller.house;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.domain.house.HouseInformation;
import com.ruoyi.system.domain.house.vo.SearchSubmitHouseInformationVO;
import com.ruoyi.system.domain.house.vo.SubmitHouseInformationVO;
import com.ruoyi.system.service.house.IHouseInformationService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @author caiden
 * @Description
 * @email 772149497@qq.com
 * @create 2021-04-05 11:46
 */
@RestController
@RequestMapping("/house-information")
public class HouseInformationController {
    @Autowired
    private IHouseInformationService iHouseInformationService;

    @PostMapping("/check-code")
    public HashMap<String,Object> checkCode(@RequestBody HouseInformation houseInformation){
        return iHouseInformationService.checkHouseInformationCode(houseInformation.getCode());
    }

    @PostMapping("/search")
    public HashMap<String,Object> queryHouseInformationList(@RequestBody SearchSubmitHouseInformationVO searchSubmitHouseInformationVO){
        return iHouseInformationService.queryHouseInformationList(searchSubmitHouseInformationVO);
    }

    @PostMapping("/view/{id}")
    public HashMap<String,Object> viewHouseInformationDetailById(@PathVariable("id")String id,@RequestBody SearchSubmitHouseInformationVO searchSubmitHouseInformationVO){
        return iHouseInformationService.viewHouseInformationDetailById(id,searchSubmitHouseInformationVO);
    }

    @PostMapping("/view")
    public HashMap<String,Object> viewHouseInformationDetail(@RequestBody SearchSubmitHouseInformationVO searchSubmitHouseInformationVO){
        return iHouseInformationService.viewHouseInformationDetail(searchSubmitHouseInformationVO);
    }

    @PostMapping("/edit")
    public HashMap<String,Object> editHouseInformationDetail(@RequestBody SubmitHouseInformationVO submitHouseInformationVO){
        return iHouseInformationService.editHouseInformationDetail(submitHouseInformationVO);
    }

    @PostMapping("/delete/{id}")
    public HashMap<String,Object> deleteHouseInformationDetail(@PathVariable("id")String id){
        return iHouseInformationService.deleteHouseInformationDetail(id);
    }

    @PostMapping("/add")
    public HashMap<String,Object> add(@RequestBody SubmitHouseInformationVO submitHouseInformationVO){
        try {
            return iHouseInformationService.addHouseInformation(submitHouseInformationVO);
        } catch (Exception e) {
            HashMap<String,Object> result = new HashMap<>();
            result.put("code","10000");
            result.put("msg",e.getMessage());
            return result;
        }
    }
}
